package org.vison.wonfu.framework.run;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.Banner;
import org.springframework.boot.ResourceBanner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.vison.wonfu.framework.commons.Constants;

@Slf4j
public class Runner {
    public static void run(String appId,Class<?> sourceClass,String... args) {
        Assert.hasText(appId,"[APPID]应用ID不能为空,请添加-Dwonfu.app.id启动参数");
        Resource banner = new ClassPathResource("banner.txt");
        Banner.Mode bannerMode = Banner.Mode.CONSOLE;
        new SpringApplicationBuilder()
                .sources(sourceClass)
                .bannerMode(bannerMode)
                .banner(new ResourceBanner(banner))
                .logStartupInfo(true)
                .web(WebApplicationType.SERVLET)
                .run(args);
        Constants.setAppid(appId);
        log.info("{} 启动成功",appId);
    }

}
